package com.thoughtworks.turtlemock.expression;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

public class Conversion {

    private final static Map CONVERSION_MAP = new HashMap();

    static {
        CONVERSION_MAP.put(new Pair(Measurement.MILLIMETER, Measurement.CENTIMETER), new BigDecimal(0.1));
        CONVERSION_MAP.put(new Pair(Measurement.CENTIMETER, Measurement.MILLIMETER), new BigDecimal(10));
    }

    public static double rate(String from, String to) {
        if (from.equals(to)) {
            return 1;
        }
        BigDecimal rate = (BigDecimal) CONVERSION_MAP.get(new Pair(from, to));
        return rate.doubleValue();
    }
}
